let  nodemailer = require("nodemailer");
let  message = require("./message");
let code_message = require("./JsonFileOprate")
let transporter = nodemailer.createTransport({
    service:'qq',
    host:'smtp.qq.com',
    secureConnection: true,
    auth: {
        user:'790467788@qq.com',
        //pass:'xlphgavuwzbubbjj'
        pass:'mxflpusrdkerbbdb'
    }
});

let scheduledEmail = function (recipient,content){
    let emailParameter = {
        from:"790467788@qq.com",
        to:`${recipient}`,
        subject:"Mission Email Remind",
        text:"text plain",
        html:`<h1>Mission Email Remind</h1><h3>${content}</h3>`
    }

    transporter.sendMail(
        emailParameter
, function(error, info){
        if(error){
            console.log(error);
        }
        console.log(info);
    })
}
module.exports = {
    taskEmailNotification :function (req,res) {
        let date = Date.parse(req.body.remindTime)
        let restSeconds=Math.round(date/1000) - Math.round(new Date().getTime()/1000)
        if (restSeconds>=60) {
            setTimeout(
                scheduledEmail,restSeconds*1000,req.body.recipient,req.body.content
            )
            res.json(new message("216",null,code_message['216']))
        }
        else {
            res.json(new message("228",null,code_message['228']))
        }

    },
}